package dome1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-06-22
 * Time: 21:04
 */

//泛型方法
//泛型方法的上界
//代表将来传进来的类型必须实现了Comparab接口  ,  指定的E要么是子类要么是本身!!!
class Alg1 {
    public static <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Test5 {
    public static void main(String[] args) {
        Integer[] array = {4,6,1,34,8,90,43,233,5,7,5};
        Integer val = Alg1.findMax(array); //这里的<Integer>可以省略...
        System.out.println(val);
    }
}
